/*
** Open a print page in a new window, fill it with info and optionally print it
*/

// Add link behaviors
$(document).ready(function(){
	$("a.print").attr("href", "javascript:void(0)");
	$("a.print").click(function(){
		openPrint( $(this).attr("rel"), true);
		});
	});
// First open up the window and wait for the DOM to load
function openPrint(src, print){
	// open the print window
	var printWindow = window.open("print.htm", "printwindow", "status=1,toolbar=1,location=1,menubar=1,resizable=1,scrollbars=1");

	// wait 5 seconds until the page loads so we can access the page DOM.
	window.setTimeout(function(){
		printContent(printWindow, print);
		}, 5000 );
}

// Next fill in our values and optionally print
function printContent(printWindow, print)
{
	// collect values
    var content = $(".newscontent").html();
	// fill in print values	
	 if(printWindow!=null)
     {
		printWindow.setTimeout(function()
	  	 {
	  	     printWindow.document.getElementById("content-print").innerHTML = content;			
			if (print) 
			{
				printWindow.setTimeout(function()
				{
							if(printWindow.print())
							{
								
							}								
				}, 2000);
			}
		 }, 3000 );	
	  }
	
	// If we're printing, print the window
	// Need a pause here to give time for the info to fill in.	
	
	return false;
}


